package com.cbgolf.oa.views;

import static com.cbgolf.oa.R.id.a_statistics_linechart_name_tv;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;
import com.cbgolf.oa.R;
import com.cbgolf.oa.base.BaseViewNew;
import com.cbgolf.oa.contract.IStatisticsContract.IStatisticsView;
import com.cbgolf.oa.contract.IStatisticsContract.IStatisticsWaiter;
import com.cbgolf.oa.entity.ChartBean;
import com.cbgolf.oa.event.EventStatistics;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.util.DateUtil;
import com.cbgolf.oa.util.ErrorUtil;
import com.cbgolf.oa.util.ViewUtils;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart;
import org.xutils.view.annotation.ViewInject;

/**
 * @author lq
 * @date 2018/5/7
 */

public class StatisticsNewView extends BaseViewNew implements IStatisticsView {

  //top
  @ViewInject(R.id.topBack_ll)
  private View topBack;
  @ViewInject(R.id.title_tv)
  private TextView titleTv;
  //body
  @ViewInject(R.id.a_statistics_name_tv)
  private TextView parkNameTv;
  @ViewInject(R.id.a_statistics_yingyedian_filter_ll)
  private View filterPointView;
  @ViewInject(R.id.a_statistics_yingyedian_tv)
  private TextView filterPointTv;
  @ViewInject(R.id.a_statistics_filter_date_type_ll)
  private View filterDateView;
  @ViewInject(R.id.a_statistics_filter_date_type_tv)
  private TextView filterDateTv;
  @ViewInject(R.id.a_statistics_date_last_tv)
  private TextView lastTv;
  @ViewInject(R.id.a_statistics_date_tv)
  private TextView dateTv;
  @ViewInject(R.id.a_statistics_date_next_tv)
  private TextView nextTv;
  //
  @ViewInject(R.id.a_statistics_date_ll)
  private View dateTypeChooseView;
  @ViewInject(R.id.a_statistics_day_tv)
  private TextView dayTv;
  @ViewInject(R.id.a_statistics_week_tv)
  private TextView weekTv;
  @ViewInject(R.id.a_statistics_month_tv)
  private TextView monthTv;
  @ViewInject(R.id.a_statistics_quarter_tv)
  private TextView quarterTv;
  @ViewInject(R.id.a_statistics_year_tv)
  private TextView yearTv;
  //money
  @ViewInject(R.id.a_statistics_money_all_tv)
  private TextView allNumTv;
  @ViewInject(R.id.a_statistics_money_all_compare_tv)
  private TextView allCompareTv;
  @ViewInject(R.id.a_statistics_money_jiru_tv)
  private TextView inCludeNumTv;
  @ViewInject(R.id.a_statistics_money_jiru_compare_tv)
  private TextView inCludeCompareTv;
  @ViewInject(R.id.a_statistics_money_not_clude_tv)
  private TextView noCludeNumTv;
  @ViewInject(R.id.a_statistics_money_not_clude_compare_tv)
  private TextView noCludeCompareTv;
  //chart
  @ViewInject(R.id.a_statistics_money_this_tv)
  private TextView thisNumTv;
  @ViewInject(R.id.a_statistics_money_this_compare_tv)
  private TextView thisCompareTv;
  @ViewInject(R.id.a_statistics_money_linechart)
  private LineChart lineChart;
  @ViewInject(R.id.a_statistics_pay_type_barchart)
  private BarChart barChart;
  //
  @ViewInject(R.id.a_statistics_all_ll)
  private View allView;
  @ViewInject(R.id.a_statistics_include_ll)
  private View includeView;
  @ViewInject(R.id.a_statistics_not_include_ll)
  private View notIncludeView;
  //name
  @ViewInject(R.id.a_statistics_all_name_tv)
  private TextView allNameTv;
  @ViewInject(R.id.a_statistics_include_name_tv)
  private TextView includeNameTv;
  @ViewInject(R.id.a_statistics_not_include_name_tv)
  private TextView notIncludeNameTv;
  @ViewInject(a_statistics_linechart_name_tv)
  private TextView lineChartNameTv;
  @ViewInject(R.id.a_statistics_barchart_name_tv)
  private TextView barChartNameTv;
  //
  @ViewInject(R.id.a_statistics_linechart_this_tv)
  private TextView lineThisTv;
  @ViewInject(R.id.a_statistics_linechart_last_tv)
  private TextView lineLastTv;
  @ViewInject(R.id.a_statistics_barchart_this_tv)
  private TextView barThisTv;
  @ViewInject(R.id.a_statistics_barchart_last_tv)
  private TextView barLastTv;

  @ViewInject(R.id.a_statistics_order_tv)
  private TextView orderTv;
  private IStatisticsWaiter worker;
  private int mType;

  public StatisticsNewView(Activity act, IStatisticsWaiter waiter, int type) {
    this.worker = waiter;
    this.mType = type;
    ViewUtils.autoInjectAllField(this, act);
    super.init(act);
  }

  @Override
  protected void setViews() {
    ViewUtils.setText(titleTv, worker.getActivityTitle());
    ViewUtils.setText(parkNameTv, DataUtil.getCourseName());
    ViewUtils.setText(dateTv, DateUtil.stampToDateyMdHm2(System.currentTimeMillis()));
    setNextTvLive(false);
    setViewInfo();
    lineChart.setNoDataText(ErrorUtil.NODATA);
    barChart.setNoDataText(ErrorUtil.NODATA);
    lineChart.setNoDataTextColor(ContextCompat.getColor(context, R.color.text_gray));
    barChart.setNoDataTextColor(ContextCompat.getColor(context, R.color.text_gray));
  }

  public void setNextTvLive(boolean isLive) {
    nextTv.setEnabled(isLive);
    nextTv.setTextColor(isLive ? ContextCompat.getColor(context, R.color.bg_blue)
        : ContextCompat.getColor(context, R.color.text_hint));
  }

  public void setViewInfo() {
    switch (mType) {
      case DataManager.STATISTICS_BUSINESS_ALL:
        ViewUtils.setText(titleTv, "营业统计");
        worker.getPointList();
        break;
      case DataManager.STATISTICS_BOOK_ALL:
        ViewUtils.setText(titleTv, "预订统计");
        filterPointView.setVisibility(View.GONE);
        allNameTv.setText("总预订(人)");
        includeNameTv.setText("到场(人)");
        notIncludeNameTv.setText("未到场(人)");
        lineChartNameTv.setText("预订人数");
        barChartNameTv.setText("预订渠道");
        break;
      case DataManager.STATISTICS_CADDIE_ALL:
        ViewUtils.setText(titleTv, "球僮统计");
        filterPointView.setVisibility(View.GONE);
        allNameTv.setText("总出场次(次)");
        includeNameTv.setText("平均场次(次)");
        notIncludeNameTv.setText("平均时长(分钟)");
        lineChartNameTv.setText("出场人次");
        barChartNameTv.setText("出场次数");
        setBackroundGradient();
        break;
      case DataManager.STATISTICS_BILL_ALL:
        ViewUtils.setText(titleTv, "签单统计");
        allNameTv.setText("签单总额(元)");
        includeNameTv.setText("会员(元)");
        notIncludeNameTv.setText("非会员(元)");
        lineChartNameTv.setText("签单费用");
        barChartNameTv.setText("签单人");
        nextTv.setText("后一周");
        lastTv.setText("上一周");
        lineThisTv.setText("本周");
        lineLastTv.setText("上周");
        barThisTv.setText("本周");
        barLastTv.setText("上周");
        dateTv.setText("本周");
        dayTv.setVisibility(View.GONE);
        quarterTv.setVisibility(View.GONE);
        filterPointView.setVisibility(View.GONE);
        setBackroundGradient();
        worker.getPointList();
        break;
      case DataManager.STATISTICS_PLAYER_ALL:
        ViewUtils.setText(titleTv, "打球人统计");
        allNameTv.setText("总人数(人)");
        includeNameTv.setText("下场人数(人)");
        notIncludeNameTv.setText("未下场人数(人)");
        lineChartNameTv.setText("到场总人次");
        barChartNameTv.setText("身份");
        filterPointView.setVisibility(View.GONE);
        setBackroundGradient();
        worker.getPointList();
        break;
      default:
        break;
    }
    setNumDatas(new ChartBean());
  }

  private void setBackroundGradient() {
    allView.setBackgroundResource(R.drawable.gradient_blue_todeep_round5_hori);
    includeView.setBackgroundResource(R.drawable.gradient_blue_todeep_round5_hori);
    notIncludeView.setBackgroundResource(R.drawable.gradient_blue_todeep_round5_hori);
    allView.setEnabled(false);
    includeView.setEnabled(false);
    notIncludeView.setEnabled(false);
  }
  public void setNumDatas(ChartBean bean) {
//    if (Util.isEquals(classType, BOOK_TAG)) {
//      allNumTv.setText(TextUtil.textNumFloat(TypeUtil.getInt(bean.allNum)));
//      inCludeNumTv.setText(TextUtil.textNumFloat(TypeUtil.getInt(bean.inNum)));
//      noCludeNumTv.setText(TextUtil.textNumFloat(TypeUtil.getInt(bean.noCludeNum)));
//    } else {
//      allNumTv.setText(TextUtil.textNumFloat(bean.allNum));
//      inCludeNumTv.setText(TextUtil.textNumFloat(bean.inNum));
//      noCludeNumTv.setText(TextUtil.textNumFloat(bean.noCludeNum));
//    }
//
//    allCompareTv.setText(Util.isNull(bean.allRatio) ? "" : bean.allRatio);
//    inCludeCompareTv.setText(Util.isNull(bean.inRatio) ? "" : bean.inRatio);
//    noCludeCompareTv.setText(Util.isNull(bean.noCludeRatio) ? "" : bean.noCludeRatio);
//    String unit = EnumUtil.getStatisticsUnit(classType);
//    switch (dataChooseType) {
//      case ALLTYPE:
//        thisNumTv.setText((allNumTv.getText().toString() + unit));
//        thisCompareTv.setText(allCompareTv.getText().toString());
//        break;
//      case INCLUDE:
//        thisNumTv.setText((inCludeNumTv.getText().toString() + unit));
//        thisCompareTv.setText(inCludeCompareTv.getText().toString());
//        break;
//      case NOTINCLUDE:
//        if (!Util.isNull(classType) && CADDIE_TAG.equals(classType)) {
//          thisNumTv.setText((noCludeNumTv.getText().toString() + "分"));
//        } else {
//          thisNumTv.setText((noCludeNumTv.getText().toString() + unit));
//        }
//        thisCompareTv.setText(noCludeCompareTv.getText().toString());
//        break;
//      default:
//        thisNumTv.setText("");
//        thisCompareTv.setText("");
//        break;
//    }
  }


  @Override
  public void showProgress() {

  }

  @Override
  public void stopProgress() {

  }

  @Override
  public void requestFail(String msg, int code) {

  }

  @Override
  public void requestOver(EventStatistics event) {

  }
}
